<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Issue HTTP redirect</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.http-request.html">http_request</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.http-send-content-disposition.html">http_send_content_disposition</a></div>
 <div class="up"><a href="ref.http.html">HTTP 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.http-redirect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">http_redirect</h1>
  <p class="verinfo">(PECL pecl_http &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">http_redirect</span> &mdash; <span class="dc-title">Issue HTTP redirect</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.http-redirect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>http_redirect</strong></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$url</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$params</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$session</code><span class="initializer"> = false</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$status</code><span class="initializer"> = 0</span></span>
  ]]]] )</div>

  <p class="para rdfs-comment">
   Redirect to the given url.
  </p>
  <p class="para">
   The supplied <em><code class="parameter">url</code></em> will be expanded with <span class="function"><a href="function.http-build-url.html" class="function">http_build_url()</a></span>, the <em><code class="parameter">params</code></em> array will
   be treated with <span class="function"><a href="function.http-build-str.html" class="function">http_build_str()</a></span> and the session identification will be appended
   if <em><code class="parameter">session</code></em> is true. The HTTP response code will be set according to <em><code class="parameter">status</code></em>.
   You can use one of the <a href="http.constants.html#http.constants.redirect" class="link">redirect constants</a> for convenience.
   Please see <a href="http://www.faqs.org/rfcs/rfc2616" class="link external">&raquo;&nbsp;RFC 2616</a>
   for which redirect response code to use in which situation. By default PHP will decide which response status fits best.
  </p>
  <p class="para">
   To be RFC compliant, &quot;Redirecting to &lt;a&gt;URL&lt;/a&gt;.&quot; will be displayed,
   if the client doesn&#039;t redirect immediately, and the request method was another one than HEAD.
  </p>
  <p class="para">
   A log entry will be written to the redirect log, if the <a href="http.configuration.html" class="link">INI 设置</a>
   <a href="" class="link">http.log.redirect</a> is set and the redirect attempt was successful.
  </p>

 </div>

 <div class="refsect1 parameters" id="refsect1-function.http-redirect-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">url</code></em></dt>

     <dd>

      <p class="para">
       the URL to redirect to
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">params</code></em></dt>

     <dd>

      <p class="para">
       associative array of query parameters
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">session</code></em></dt>

     <dd>

      <p class="para">
       whether to append session information
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">status</code></em></dt>

     <dd>

      <p class="para">
       custom response status code
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.http-redirect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回 <strong><code>FALSE</code></strong> 或在成功时返回<em class="emphasis">出口</em>信息 with the specified redirection status code.
   要知道“出口”的含义请查阅
<a href="http.configuration.html" class="link">INI 设置</a>
<a href="" class="link">http.force_exit</a>。
  </p>
 </div>


 


 


 <div class="refsect1 examples" id="refsect1-function.http-redirect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4280">
    <p><strong>Example #1 A <span class="function"><strong>http_redirect()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />http_redirect</span><span style="color: #007700">(</span><span style="color: #DD0000">"relpath"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"name"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"value"</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">HTTP_REDIRECT_PERM</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
HTTP/1.1 301 Moved Permanently
X-Powered-By: PHP/5.2.2
Content-Type: text/html
Location: http://www.example.com/curdir/relpath?name=value&amp;PHPSESSID=abc

Redirecting to &lt;a href=&quot;http://www.example.com/curdir/relpath?name=value&amp;PHPSESSID=abc&quot;&gt;http://www.example.com/curdir/relpath?name=value&amp;PHPSESSID=abc&lt;/a&gt;.
</pre></div>
    </div>
   </div>
  </p>
 </div>



 <div class="refsect1 seealso" id="refsect1-function.http-redirect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">如使用 PHP 5.1.0 及以后版本中为
<a href="class.httpresponse.html" class="link">
<a href="class.httpresponse.html" class="classname">HttpResponse</a></a> 类。</li>
   </ul>
  </p>
 </div>



</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.http-request.html">http_request</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.http-send-content-disposition.html">http_send_content_disposition</a></div>
 <div class="up"><a href="ref.http.html">HTTP 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
